<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Storeroomconfig</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="scripts/jquery/jquery-1.7.1.js"></script>
	<link href="style/authority/basic_layout.css" rel="stylesheet" type="text/css">
	<link href="style/authority/common_style.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="scripts/authority/commonAll.js"></script>
	<script type="text/javascript" src="scripts/fancybox/jquery.fancybox-1.3.4.js"></script>
	<script type="text/javascript" src="scripts/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
	<link rel="stylesheet" type="text/css" href="style/authority/jquery.fancybox-1.3.4.css" media="screen"></link>
	<script type="text/javascript" src="scripts/artDialog/artDialog.js?skin=default"></script>
	<script type="text/javascript" src="scripts/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="scripts/Myscripts/alpha_add.js"></script>
	
  </head>
  
  <body>
  <script type="text/javascript">
  		var req = false;
		var table_innerhtml="";
		function createHTTP(){
		//alert("!");
			if (window.XMLHttpRequest) {
             req = new XMLHttpRequest();
         	}
         	else if (window.ActiveXObject) {
             req = new ActiveXObject("Microsoft.XMLHTTP");
         	}
         	if(!req)
         	alert("no req!");
		}
		function getrefresh(){
		createHTTP();
		var storeroom_name = document.getElementById("storeroom_name_id").value;
		if(storeroom_name==null)
			storeroom_name="";
		var storeroom_address = document.getElementById("storeroom_address_id").value;
		if(storeroom_address==null)
			storeroom_address="";
		var storeroom_manager = document.getElementById("storeroom_manager_id").value;
		if(storeroom_manager==null)
			storeroom_manager="";
		var storeroom_level = document.getElementById("storeroom_level_id").value;
		if(storeroom_level==null)
			storeroom_level="";
		//alert(storeroom_name);
		req.open("post","servlet/Storeroomconfigservlet",true);
        req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        req.onreadystatechange=updatePage;
  		req.send("storeroom_name="+encodeURI(encodeURI(storeroom_name))+"&storeroom_address="+encodeURI(encodeURI(storeroom_address))+"&storeroom_manager="+encodeURI(encodeURI(storeroom_manager))+"&storeroom_level="+encodeURI(encodeURI(storeroom_level))+"&action=refresh");
		}
		function updatePage(){
			if(req.readyState==4)
			{
				//alert(req.status);
				if(req.status=200)
				{
					var xmlDoc = req.responseXML.documentElement;
  					var xstorerooms = xmlDoc.getElementsByTagName("storeroom");
  					var storerooms_table = document.getElementById("storerooms_table");
  					var temp_table_innerHTML = table_innerhtml;
  					//alert(temp_table_innerHTML);
  					for(var i=0;i<xstorerooms.length;++i)
  					{
  						var t_name = xstorerooms[i].childNodes[0].firstChild.nodeValue;
  						var t_address = xstorerooms[i].childNodes[1].firstChild.nodeValue;
  						var t_manager = xstorerooms[i].childNodes[2].firstChild.nodeValue;
  						var t_level = xstorerooms[i].childNodes[3].firstChild.nodeValue;
  						var selectstring ="";
  						if(t_level=="sub")
  							selectstring = "<select id=\"storeroom"+i+"_level\"><option value = \"sub\" selected >sub<option value = \"center\">center</select>";
  						else
  							selectstring = "<select id=\"storeroom"+i+"_level\"><option value = \"sub\">sub<option value = \"center\" selected >center</select>";
  						var t_id = xstorerooms[i].childNodes[4].firstChild.nodeValue;
  						temp_table_innerHTML+="<tr><td><input class=\"ui_input_txt02\" type=\"text\" value=\""+t_name+"\" id=\"storeroom"+i+"_name\"/></td><td><input class=\"ui_input_txt02\" type=\"text\" value=\""+t_address+"\" id=\"storeroom"+i+"_address\"/></td><td><input class=\"ui_input_txt02\" type=\"text\" value=\""+t_manager+"\" id=\"storeroom"+i+"_manager\"/></td><td>"+selectstring+"</td><td><input class=\"ui_input_btn01\" type=\"button\" value=\"修改\" onclick=\"getmod("+i+")\"/> <input class=\"ui_input_btn01\" type=\"button\" value=\"删除\" onclick = \"getdelete("+i+")\"/> <input type=\"hidden\" value=\""+t_id+"\" id = \"storeroom"+i+"_id\"></td></tr>";
  					}
  					temp_table_innerHTML+="<tr><td><input class=\"ui_input_txt02\" type=\"text\"id=\"storeroomadd_name\"/></td><td><input class=\"ui_input_txt02\" type=\"text\" id=\"storeroomadd_address\"/></td><td><input class=\"ui_input_txt02\" type=\"text\" id=\"storeroomadd_manager\"/></td><td><select id=\"storeroomadd_level\"><option value = \"sub\" selected>sub<option value = \"center\"  >center</select></td><td><input class=\"ui_input_btn01\" type = \"button\" onclick = \"getadd()\" value = \"添加\"/></td></tr>";
  					storerooms_table.innerHTML=temp_table_innerHTML;
				}
			}
		}
		function getmod(){
			createHTTP();
			var i = arguments[0];
			var storeroomi_name = document.getElementById("storeroom"+i+"_name").value;
			if(storeroomi_name==null)
				storeroomi_name="";
			var storeroomi_address = document.getElementById("storeroom"+i+"_address").value;
			if(storeroomi_address==null)
				storeroomi_address="";
			var storeroomi_manager = document.getElementById("storeroom"+i+"_manager").value;
			if(storeroomi_manager==null)
				storeroomi_manager="";
			var storeroomi_level = document.getElementById("storeroom"+i+"_level").value;
			if(storeroomi_level==null)
				storeroomi_level="";
			var storeroomi_id = document.getElementById("storeroom"+i+"_id").value;
			if(storeroomi_name==""||storeroomi_address==""||storeroomi_manager==""||storeroomi_level==""){
				alert("请填全信息！");
				//getrefresh();
			}
			else{
			req.open("post","servlet/Storeroomconfigservlet",true);
       		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       		req.onreadystatechange=updaterefresh;
  			req.send("storeroom_name="+encodeURI(encodeURI(storeroomi_name))+"&storeroom_address="+encodeURI(encodeURI(storeroomi_address))+"&storeroom_manager="+encodeURI(encodeURI(storeroomi_manager))+"&storeroom_level="+encodeURI(encodeURI(storeroomi_level))+"&action=mod"+"&storeroom_id="+storeroomi_id);
  			}
		}
		function getdelete(){
			createHTTP();
			var i = arguments[0];
			var storeroomi_id = document.getElementById("storeroom"+i+"_id").value;
			req.open("post","servlet/Storeroomconfigservlet",true);
       		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       		req.onreadystatechange=updaterefresh;
  			req.send("action=delete"+"&storeroom_id="+storeroomi_id);
			
		}
		function getadd(){
			createHTTP();
			var storeroomi_name = document.getElementById("storeroomadd_name").value;
			if(storeroomi_name==null)
				storeroomi_name="";
			var storeroomi_address = document.getElementById("storeroomadd_address").value;
			if(storeroomi_address==null)
				storeroomi_address="";
			var storeroomi_manager = document.getElementById("storeroomadd_manager").value;
			if(storeroomi_manager==null)
				storeroomi_manager="";
			var storeroomi_level = document.getElementById("storeroomadd_level").value;
			if(storeroomi_level==null)
				storeroomi_level="";
			if(storeroomi_name==""||storeroomi_address==""||storeroomi_manager==""||storeroomi_level==""){
				alert("请填全信息！");
			}
			else
			{
			req.open("post","servlet/Storeroomconfigservlet",true);
       		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       		req.onreadystatechange=updaterefresh;
  			req.send("storeroom_name="+encodeURI(encodeURI(storeroomi_name))+"&storeroom_address="+encodeURI(encodeURI(storeroomi_address))+"&storeroom_manager="+encodeURI(encodeURI(storeroomi_manager))+"&storeroom_level="+encodeURI(encodeURI(storeroomi_level))+"&action=add");
  			}
		}
		function updaterefresh()
		{
			if(req.readyState==4)
			{
				//alert(req.status);
				if(req.status=200)
				{
					alert("已更新");
					getrefresh();
				}
			}
		}
  </script>
  <div id = "add_alpha_id">
    <div id="container">
     <div class = "ui_content">
      <div class = "box_border">
       <div id = "box_top">搜索</div>
    	<table width = "100%" class = "table">
    		<tr><td>库房名称：</td><td><input class="ui_input_txt02" type = "text" id = "storeroom_name_id" onblur="getrefresh()"/></td><td>库房地址</td><td><input class="ui_input_txt02" type = "text" id = "storeroom_address_id" onblur="getrefresh()"/></td></tr>
    		<tr><td>库管员：</td><td><input class="ui_input_txt02" type = "text" id = "storeroom_manager_id" onblur="getrefresh()"/></td><td>库房级别</td><td><input class="ui_input_txt02" type = "text" id = "storeroom_level_id" onblur="getrefresh()"/></td></tr>
    	</table>
    	<div id = "box_bottom"> <input type="button" value = "确定" class="ui_input_btn01" onclick="getrefresh();alert('已刷新！')"></div>
    	</div>
    	</div>
    	<div class = "ui_content">
    	 <div class = "box_border">
    	 
    	<table id = "storerooms_table" width = "100%" class = "table">
    		<tr><th>库房名称</th><th>库房地址</th><th>库管员</th><th>库房级别</th><th>操作</th></tr>
    	</table>
    	 </div>
    	</div>
    </div>
    </div>
    <script type="text/javascript">
    	table_innerhtml = document.getElementById("storerooms_table").innerHTML;
    	getrefresh();
    </script>
    <script type="text/javascript">
   var eitem = document.getElementById("add_alpha_id");
   window.onload = add_alpha(eitem);
   alert(document.getElementById("test_id").value);
   </script>
  </body>
</html>
